﻿using com.ruovea.dto;
using com.ruovea.utilty;
using com.ruovea.utilty.EnumExtension;
using Microsoft.AspNetCore.Mvc;

namespace GogsWeb.Api.Controllers
{
    /// <summary>
    /// 基础响应
    /// </summary>
    public class BaseResponse : ControllerBase
    {
        #region 请求响应
        /// <summary>
        /// 返回成功消息
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        protected virtual IActionResult ToJsonResult(object data)
        {
            return Content(data.ToJson());

        }
        /// <summary>
        /// 返回成功消息
        /// </summary>
        /// <param name="info">消息</param>
        /// <returns></returns>
        protected virtual IActionResult Success(string info)
        {
            return Content(new ResParameter { code = ResponseCode.Status, msg = info }.ToJson());
        }

        /// <summary>
        /// 返回成功数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        protected virtual ActionResult Success(object data)
        {
            return Content(new ResParameter { code = ResponseCode.Status, msg = ResponseCode.Status.GetEnumText(), data = data }.ToJson());
        }

        /// <summary>
        /// 返回成功消息
        /// </summary>
        /// <param name="info">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        protected virtual ActionResult Success(string info, object data)
        {
            return Content(new ResParameter { code = ResponseCode.Status, msg = info, data = data }.ToJson());
        }

        /// <summary>
        /// 返回失败消息
        /// </summary>
        /// <param name="info">消息</param>
        /// <returns></returns>
        protected virtual ActionResult Fail(string info)
        {
            return Content(new ResParameter { code = ResponseCode.ParameterError, msg = info }.ToJson());
        }
        /// <summary>
        /// 返回失败消息
        /// </summary>
        /// <param name="info">消息</param>
        /// <param name="data">消息</param>
        /// <returns></returns>
        protected virtual ActionResult Fail(string info, object data)
        {
            return Content(new ResParameter { code = ResponseCode.ParameterError, msg = info, data = data }.ToJson());
        }
        #endregion
    }
}
